<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>消息订阅与发布</title>
  <script src="../../src/pub-sub/index.js"></script>
</head>
<body>
  <script>
    //订阅一个频道
    let pid = PubSub.subscribe('pay',data=>{
      console.log('商家接到了订单，准备开始制作',data)
    })

    let pid2 = PubSub.subscribe('pay',data=>{
      console.log('骑手接到了订单，准备开始去取餐',data)
    })

    PubSub.subscribe('cancel',data=>{
      console.log('商家接到了取消的请求')
    })

    PubSub.publish('pay',{
      title:'鱼香肉丝饭',
      price:20,
      pos:'三年二班'
    })

    PubSub.unsubscribe(pid)
    console.log(pid,pid2);

  </script>
</body>
</html>